// 字典管理
import request from '@/utils/request'

// 新增字典
export function addDictInfo(data) {
  return request({
    method: 'post',
    url: '/resource/dict/addDict',
    data: data
  })
}

// 新增字典值
export function addDictItem(data) {
  return request({
    method: 'post',
    url: '/resource/dict/addItem',
    data: data
  })
}

// 查询字典列表
export function queryDictList(params) {
  return request({
    method: 'get',
    url: '/resource/dict/query',
    params
  })
}
// 查询指定字典项
export async function queryOptions(code) {
  const res = await request({
    method: 'get',
    url: `/resource/dict/queryItem?dictCode=${code}`
  })

  if (res.data.length === 1) {
    res.data = res.data[0].resourceDictItems
  }
  return res
}

// 删除字典
export function deleteDictInfo(pkid) {
  return request({
    method: 'delete',
    url: `/resource/dict/delete?pkid=${pkid}`
  })
}
